home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / intense.exe / INTENSE.C < prev    next >
C/C++ Source or Header  |  1992-06-19  |  5KB  |  109 lines

  1. /*---------------------------------------------------------------------+
  2. | INTENSE.C                                                            |
  3. | This piece of code demonstrates how to use text-mode attributes      |
  4. | with backgrounds of 16 possible colors.  You may then use the        |
  5. | blink-bit of the text attribute as an intensity bit.                 |
  6. |                                                                      |
  7. | A text attribute is a byte that contains information on the          |
  8. | foreground and background colors of text-mode characters.  The       |
  9. | lower 4 bits (bits 0-3) of the text attribute control the            |
  10. | foreground color, or the color of the text, itself, while the        |
  11. | next 3 bits (bits 4-6) control the color of the background.          |
  12. | The uppermost bit, (bit 7) is used as a blink bit.  Normally,        |
  13. | when bit 7 is set, the foreground character blinks.                  |
  14. |                                                                      |
  15. | Because the foreground has 4 bits to describe itself, there are      |
  16. | sixteen possible colors.  Bits 0-2 provide for 8 basic, normal       |
  17. | intensity colors, and bit 3 is an intensity bit that turns the       |
  18. | 8 basic colors into high-intensity colors.                           |
  19. |                                                                      |
  20. | Because the background has 3 bits dedicated to it, the background    |
  21. | is limited to the 8 normal intensity colors. There is a way, how-    |
  22. | ever, to tell a graphics adapter to interpret the 7th bit            |
  23. | as an intensity bit for the background the same way that bit 3 is    |
  24. | interpreted as an intensity bit for the foreground.                  |
  25. |                                                                      |
  26. | For CGA adapters, set bit 5 of the CGA Mode Selection Register       |
  27. | at port address 3D8h to zero for high-intensity backgrounds.  To     |
  28. | return to blinking backgrounds, set bit 5 to 1.                      |
  29. |                                                                      |
  30. | For EGA/VTA adapters, call interrupt 10h, function 10h, sub-         |
  31. | function 03h:                                                        |
  32. |    Input:   AH=10h                                                   |
  33. |             AL=03h                                                   |
  34. |             BL=0   for high-intensity background                     |
  35. |             BL=1   for blinking background                           |
  36. |                                                                      |
  37. | For more information about text attributes, see the description      |
  38. | of function textattr() in the Borland Runtime Library reference.     |
  39. |                                                                      |
  40. | Warning! This code has been tested on CGA, EGA, and VGA adapters.    |
  41. | I don't know what would happen with other adapter types (eg, MCGA,   |
  42. | 8514, monochrome).  Let me know what happens.                        |
  43. |                                                                      |
  44. | Author:  Ron Gee, [71460,551]                                        |
  45. | Date:    6/19/92                                                     |
  46. +---------------------------------------------------------------------*/
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <graphics.h>      /* detect the type of graphics adapter */
  50. #include <conio.h>
  51. #include <dos.h>
  52.  
  53. #define VIDEO        0x10
  54. #define CGA_VID_PORT 0x03d8
  55. #define NO_BLINK     0x09
  56. #define YES_BLINK    0x41
  57.  
  58. int main()
  59. {
  60.    int gdriver, gmode;
  61.    union REGS regs;
  62.  
  63.    /* detect the type of graphics driver present */
  64.    detectgraph(&gdriver, &gmode);
  65.  
  66.    if (gdriver == grNotDetected)
  67.       {
  68.       printf("NO_BLINK:  No graphics adapter detected, gdriver = %d\n",
  69.          gdriver);
  70.       exit(8);
  71.       }
  72.  
  73.    textattr(0x2F);
  74.    clreol(); 
  75.    cprintf("Text should be bright white on normal green background");
  76.    textattr(0x1E);
  77.    cprintf("\n\rText should be yellow on normal blue background");
  78.    textattr(0x4A);
  79.    cprintf("\n\rText should be bright green on normal red background");
  80.  
  81.    /* Set the blink bit to be an intensity bit */
  82.    switch (gdriver)
  83.       {
  84.       case CGA:
  85.          outportb(CGA_VID_PORT, NO_BLINK);
  86.          break;
  87.       case EGA:
  88.       case VGA:
  89.          regs.h.ah = 0x10;
  90.          regs.h.al = 0x03;
  91.          regs.h.bl = 0x00;
  92.          int86(VIDEO, ®s, ®s);
  93.          break;
  94.       default:
  95.          printf("\nWarning:  Graphics adapter must be CGA, EGA, or VGA"
  96.             " for intense background\n");
  97.          break;
  98.       }
  99.  
  100.    textattr(0xA5);
  101.    cprintf("\n\rText should be magenta on bright green background");
  102.    textattr(0x9E);
  103.    cprintf("\n\rText should be yellow on bright blue background");
  104.    textattr(0xCE);
  105.    cprintf("\n\rText should be yellow on bright red background");
  106.  
  107.    return(0);
  108. }
  109.